from rest_framework import serializers
from .models import *

# 订单信息
class OrderInfoSer(serializers.ModelSerializer):

    user_name = serializers.SerializerMethodField(read_only=True)
    def get_user_name(self, obj):
        return obj.user.username

    status_name = serializers.SerializerMethodField(read_only=True)

    def get_status_name(self, obj):
        return obj.get_status_display()

    class Meta:
        model = OrderInfo
        fields = "__all__"
        read_only_fields = ["order_id",]


# 订单商品的序列化器
class OrderGoodsSer(serializers.ModelSerializer):

    class Meta:
        model = OrderGoods
        fields = "__all__"
